function uploadProgress(file, bytesLoaded) {

	try {
		var percent = Math.ceil((bytesLoaded / file.size) * 100);

		var progress = new FileProgress(file,  this.customSettings.upload_target);
		progress.setProgress(percent);
		if (percent === 100) {
			progress.setStatus("Создание превью...");
			progress.toggleCancel(false, this);
		} else {
			progress.setStatus("Загрузка...");
			progress.toggleCancel(true, this);
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccess(file, serverData) {
	try {
		var progress = new FileProgress(file,  this.customSettings.upload_target);				
		
		if (serverData.substring(0, 5) !== "ERROR") {						
			src_arr = serverData.split('::', 2);			
			addImage(src_arr[0], src_arr[1]);
			
			progress.setStatus("Превью создано.");
			progress.toggleCancel(false);

			var count = parseInt($('#span_photo_count').html())+1;
			$('#span_photo_count').html(count);				
			$('#fieldset_photo_count').show();	
			
			var link = $('#photo_link').attr('rel');
			$('#photo_link').attr('href', link);
			$('#photo_link').attr('onclick', '');
			
		} else {
			addImage("images/error.gif");
			progress.setStatus("Error.");
			progress.toggleCancel(false);
			alert(serverData);

		}


	} catch (ex) {
		this.debug(ex);
	}
}

function uploadComplete(file) {
	try {
		/*  I want the next upload to continue automatically so I'll call startUpload here */
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} else {
			var progress = new FileProgress(file,  this.customSettings.upload_target);
			progress.setComplete();
			progress.setStatus("Все изображения загружены.");
			progress.toggleCancel(false);
		}
	} catch (ex) {
		this.debug(ex);
	}
}



function addImage(src, src2) 
{
	var str = '<img src="'+src+'" onclick="insert_tiny_img(\''+src2+'\')"/>';	
	$('#thumbnails img:last').after(str);
}



